<template>
  <div class="writing-container">
    <div class="background-wrapper"></div>
    <div class="content">
      <!-- 导航栏组件 -->
      <Navbar />

      <!-- AI写作页面主要内容 -->
      <section class="writing-main">
        <div class="writing-content">
          <h2 class="page-title">AI文字创作</h2>
          <p class="page-description">
            通过三步式分步引导流程，轻松创作属于您的独特文字作品
          </p>
          
          <!-- 创作步骤指示器 -->
          <div class="steps-indicator">
            <div 
              v-for="(step, index) in steps" 
              :key="index"
              :class="['step', { active: currentStep >= index, completed: currentStep > index }]"
            >
              <div class="step-number">{{ index + 1 }}</div>
              <div class="step-label">{{ step }}</div>
            </div>
          </div>
          
          <!-- 第一步：文体与主题选择 -->
          <div v-show="currentStep === 0" class="creation-step">
            <h3>选择文体与主题</h3>
            <div class="genre-selection">
              <div class="tags-container">
                <div 
                  v-for="genre in writingGenres" 
                  :key="genre"
                  :class="['tag', { selected: selectedGenres.includes(genre) }]"
                  @click="toggleGenre(genre)"
                >
                  {{ genre }}
                </div>
              </div>
              
              <div class="selected-combination" v-if="selectedGenres.length">
                <h4>已选文体组合：</h4>
                <div class="combination-tags">
                  <span v-for="genre in selectedGenres" :key="genre" class="combination-tag">{{ genre }}</span>
                </div>
              </div>
              
              <!-- 主题方向选项 -->
              <div class="theme-selection" v-if="availableThemes.length > 0">
                <h4>主题方向：</h4>
                <div class="tags-container">
                  <div 
                    v-for="theme in availableThemes" 
                    :key="theme"
                    :class="['tag', 'theme-tag', { selected: selectedThemes.includes(theme) }]"
                    @click="toggleTheme(theme)"
                  >
                    {{ theme }}
                  </div>
                </div>
              </div>
            </div>
            
            <div class="step-actions">
              <button class="next-btn" @click="nextStep" :disabled="!canProceedToStep1">下一步</button>
            </div>
          </div>
          
          <!-- 第二步：内容细节引导 -->
          <div v-show="currentStep === 1" class="creation-step">
            <h3>内容细节引导</h3>
            <div class="content-guidance">
              <div class="recommendation-section" v-if="recommendedKeywords.length || structureSuggestions">
                <div class="recommendation-group" v-if="recommendedKeywords.length">
                  <h4>推荐关键词（点击添加）</h4>
                  <div class="tags-container">
                    <div 
                      v-for="keyword in recommendedKeywords" 
                      :key="keyword"
                      class="tag recommendation-tag"
                      @click="addKeyword(keyword)"
                    >
                      {{ keyword }}
                    </div>
                  </div>
                </div>
                
                <div class="recommendation-group" v-if="structureSuggestions">
                  <h4>结构建议</h4>
                  <div class="suggestion-content">
                    {{ structureSuggestions }}
                  </div>
                </div>
              </div>
              
              <div class="input-section">
                <div class="input-group">
                  <h4>详细创作要求</h4>
                  <textarea 
                    v-model="contentRequirements"
                    placeholder="请输入详细的创作要求，例如：'主角是少年宇航员''语言风格简洁有力''包含哲学思考'"
                    class="requirements-input"
                  ></textarea>
                </div>
                
                <div class="input-group">
                  <h4>自定义关键词</h4>
                  <div class="keyword-input-area">
                    <input 
                      v-model="newKeyword"
                      @keyup.enter="addCustomKeyword"
                      placeholder="输入关键词后按回车添加"
                      class="keyword-input"
                    >
                    <button @click="addCustomKeyword" class="add-keyword-btn">添加</button>
                  </div>
                  
                  <div class="selected-keywords" v-if="customKeywords.length">
                    <h4>已添加关键词：</h4>
                    <div class="keywords-container">
                      <span 
                        v-for="(keyword, index) in customKeywords" 
                        :key="index"
                        class="keyword-tag"
                      >
                        {{ keyword }}
                        <button class="remove-keyword" @click="removeKeyword(index)">×</button>
                      </span>
                    </div>
                  </div>
                </div>
              </div>
            </div>
            
            <div class="step-actions">
              <button class="prev-btn" @click="prevStep">上一步</button>
              <button class="next-btn" @click="nextStep" :disabled="!canProceedToStep2">下一步</button>
            </div>
          </div>
          
          <!-- 第三步：生成与编辑 -->
          <div v-show="currentStep === 2" class="creation-step">
            <h3>生成与编辑</h3>
            <div class="generation-section">
              <div class="generation-summary">
                <h4>创作摘要</h4>
                <div class="summary-content">
                  <p><strong>文体组合：</strong>{{ selectedGenres.join(' + ') || '未选择' }}</p>
                  <p><strong>主题方向：</strong>{{ selectedThemes.join('、') || '未选择' }}</p>
                  <p><strong>创作要求：</strong>{{ contentRequirements || '无' }}</p>
                  <p><strong>自定义关键词：</strong>{{ customKeywords.length ? customKeywords.join('、') : '无' }}</p>
                </div>
              </div>
              
              <div class="generation-actions">
                <button 
                  class="generate-btn" 
                  @click="generateText"
                  :disabled="isGenerating"
                >
                  {{ isGenerating ? '生成中...' : '生成文字' }}
                </button>
              </div>
              
              <!-- 生成状态 -->
              <div v-if="isGenerating" class="generation-status">
                <div class="loading-spinner"></div>
                <p>正在为您创作文字作品，请稍候...</p>
              </div>
              
              <!-- 文字编辑器 -->
              <div v-if="textGenerated" class="editor-section">
                <div class="editor-header">
                  <h4>作品编辑器</h4>
                  <div class="word-count">字数: {{ wordCount }}</div>
                </div>
                
                <div class="editor-container">
                  <div class="editor-toolbar">
                    <button class="toolbar-btn" @click="formatText('bold')" title="加粗">𝐁</button>
                    <button class="toolbar-btn" @click="formatText('italic')" title="斜体">𝘐</button>
                    <button class="toolbar-btn" @click="formatText('underline')" title="下划线">𝑈</button>
                    <button class="toolbar-btn" @click="formatText('h1')" title="标题1">H1</button>
                    <button class="toolbar-btn" @click="formatText('h2')" title="标题2">H2</button>
                    <button class="toolbar-btn" @click="undo" title="撤销">↩️</button>
                    <button class="toolbar-btn" @click="redo" title="重做">↪️</button>
                  </div>
                  
                  <div 
                    ref="editorRef"
                    contenteditable="true"
                    class="editor-content"
                    @input="updateWordCount"
                    v-html="generatedText"
                  ></div>
                </div>
                
                <div class="editor-actions">
                  <button class="action-btn" @click="regenerateText">重新生成</button>
                  <button class="action-btn primary" @click="saveText">保存作品</button>
                </div>
              </div>
            </div>
          </div>
        </div>
      </section>

      <!-- 底部 -->
      <footer class="footer">
        <p>© 2025 AI 艺术创作平台 - 让创意无界，让 AI 赋能艺术创作</p>
      </footer>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, computed, nextTick, onMounted } from 'vue'
import { useRouter } from 'vue-router'
import Navbar from '../components/Navbar.vue'

const router = useRouter()

// 用户信息
const username = ref('')
const userInfo = ref<any>(null)

// 控制用户信息面板显示
const showUserProfile = ref(false)
// 用于延迟隐藏面板的定时器
const hideTimeout = ref<number | null>(null)

// 创作步骤
const currentStep = ref(0)
const steps = ref(['文体选择', '内容引导', '生成编辑'])

// 文体标签
const writingGenres = ref([
  '科幻短篇', '抒情散文', '现代诗歌', '微型小说', 
  '广告文案', '新闻报道', '学术论文', '剧本创作',
  '童话故事', '历史小说', '悬疑推理', '哲理随笔'
])

// 选中的文体
const selectedGenres = ref<string[]>([])

// 主题方向（根据选中的文体动态变化）
const genreThemes: Record<string, string[]> = {
  '科幻短篇': ['星际旅行', '时间循环', '人工智能', '外星文明', '赛博朋克', '太空殖民'],
  '抒情散文': ['自然风光', '人生感悟', '亲情友情', '季节变迁', '旅途见闻', '心灵独白'],
  '现代诗歌': ['自由诗', '意象派', '象征主义', '城市生活', '情感表达', '社会批判'],
  '微型小说': ['意外结局', '人物刻画', '情节反转', '生活片段', '心理描写', '社会现象'],
  '广告文案': ['产品推广', '品牌故事', '促销活动', '社交媒体', '视频脚本', '宣传册'],
  '新闻报道': ['时事热点', '社会民生', '科技发展', '文化娱乐', '体育赛事', '国际动态'],
  '学术论文': ['文献综述', '实验研究', '理论分析', '数据分析', '结论讨论', '参考文献'],
  '剧本创作': ['电影剧本', '电视剧本', '舞台剧', '广播剧', '短视频脚本', '动画剧本']
}

// 选中的主题
const selectedThemes = ref<string[]>([])

// 可用的主题（根据选中的文体计算）
const availableThemes = computed(() => {
  const themes: string[] = []
  selectedGenres.value.forEach(genre => {
    if (genreThemes[genre]) {
      themes.push(...genreThemes[genre])
    }
  })
  return [...new Set(themes)] // 去重
})

// 推荐关键词和结构建议（根据选择的文体和主题动态生成）
const recommendedKeywords = computed(() => {
  const keywords: string[] = []
  
  // 根据文体和主题推荐关键词
  if (selectedGenres.value.includes('科幻短篇') && selectedThemes.value.includes('星际旅行')) {
    keywords.push('外星文明', '时空穿越', '飞船故障', 'zero gravity', '异星景观')
  }
  if (selectedGenres.value.includes('抒情散文') && selectedThemes.value.includes('自然风光')) {
    keywords.push('山川河流', '花草树木', '四季变换', '鸟语花香', '田园风光')
  }
  if (selectedGenres.value.includes('现代诗歌') && selectedThemes.value.includes('情感表达')) {
    keywords.push('爱恨情仇', '内心独白', '情感波动', '诗意语言', '象征手法')
  }
  if (selectedGenres.value.includes('广告文案') && selectedThemes.value.includes('产品推广')) {
    keywords.push('产品特点', '用户痛点', '解决方案', '品牌形象', '购买动机')
  }
  
  return [...new Set(keywords)] // 去重
})

const structureSuggestions = computed(() => {
  if (selectedGenres.value.includes('科幻短篇') && selectedThemes.value.includes('星际旅行')) {
    return '开头设置悬念、中间展开冲突、结尾留下余味'
  }
  if (selectedGenres.value.includes('抒情散文') && selectedThemes.value.includes('人生感悟')) {
    return '以景入情、情景交融、卒章显志'
  }
  if (selectedGenres.value.includes('现代诗歌') && selectedThemes.value.includes('自由诗')) {
    return '意象鲜明、节奏感强、情感真挚'
  }
  if (selectedGenres.value.includes('微型小说') && selectedThemes.value.includes('意外结局')) {
    return '铺垫伏笔、层层递进、出人意料'
  }
  return ''
})

// 内容要求和自定义关键词
const contentRequirements = ref('')
const customKeywords = ref<string[]>([])
const newKeyword = ref('')

// 生成状态
const isGenerating = ref(false)
const textGenerated = ref(false)
const generatedText = ref('')

// 编辑器相关
const editorRef = ref<HTMLElement | null>(null)
const wordCount = ref(0)

// 计算属性：是否可以进入下一步
const canProceedToStep1 = computed(() => {
  return selectedGenres.value.length > 0
})

const canProceedToStep2 = computed(() => {
  return contentRequirements.value.trim() !== '' || customKeywords.value.length > 0
})

// 切换文体标签
const toggleGenre = (genre: string) => {
  const index = selectedGenres.value.indexOf(genre)
  if (index > -1) {
    selectedGenres.value.splice(index, 1)
    // 清除不再适用的主题
    selectedThemes.value = selectedThemes.value.filter(theme => 
      availableThemes.value.includes(theme)
    )
  } else {
    selectedGenres.value.push(genre)
  }
}

// 切换主题标签
const toggleTheme = (theme: string) => {
  const index = selectedThemes.value.indexOf(theme)
  if (index > -1) {
    selectedThemes.value.splice(index, 1)
  } else {
    selectedThemes.value.push(theme)
  }
}

// 添加推荐关键词
const addKeyword = (keyword: string) => {
  if (!customKeywords.value.includes(keyword)) {
    customKeywords.value.push(keyword)
  }
}

// 添加自定义关键词
const addCustomKeyword = () => {
  if (newKeyword.value.trim() !== '' && !customKeywords.value.includes(newKeyword.value.trim())) {
    customKeywords.value.push(newKeyword.value.trim())
    newKeyword.value = ''
  }
}

// 移除关键词
const removeKeyword = (index: number) => {
  customKeywords.value.splice(index, 1)
}

// 下一步
const nextStep = () => {
  if (currentStep.value < 2) {
    currentStep.value++
  }
}

// 上一步
const prevStep = () => {
  if (currentStep.value > 0) {
    currentStep.value--
  }
}

// 生成文字作品
const generateText = () => {
  isGenerating.value = true
  
  // 模拟生成过程
  setTimeout(() => {
    isGenerating.value = false
    textGenerated.value = true
    
    // 模拟生成的文字内容
    generatedText.value = `<h1>${selectedThemes.value[0] || '我的作品'}</h1>
    <p>这是一段由AI生成的${selectedGenres.value.join(' + ')}作品。</p>
    <p>根据您的要求，作品包含了以下关键词：${customKeywords.value.join('、')}</p>
    <p>内容概要：${contentRequirements.value || '暂无具体要求'}</p>`
    
    // 更新字数统计
    updateWordCount()
  }, 3000)
}

// 更新字数统计
const updateWordCount = () => {
  if (editorRef.value) {
    const text = editorRef.value.innerText || ''
    wordCount.value = text.length
  }
}

// 格式化文本
const formatText = (command: string) => {
  document.execCommand(command, false)
  updateWordCount()
}

// 撤销操作
const undo = () => {
  document.execCommand('undo', false)
  updateWordCount()
}

// 重做操作
const redo = () => {
  document.execCommand('redo', false)
  updateWordCount()
}

// 重新生成
const regenerateText = () => {
  textGenerated.value = false
  generateText()
}

// 保存作品
const saveText = () => {
  alert('作品保存功能已触发')
}

// 跳转到个人中心
const goToProfile = () => {
  router.push('/profile')
}

// 跳转到登录页
const goToLogin = () => {
  router.push('/')
}

// 处理登出
const handleLogout = async () => {
  try {
    // 清除本地用户信息
    localStorage.removeItem('userInfo')
    userInfo.value = null
    username.value = ''
    
    // 跳转到登录页
    router.push('/')
  } catch (error: any) {
    console.error('退出失败:', error)
    // 即使失败也清空本地信息并跳转到登录页
    localStorage.removeItem('userInfo')
    userInfo.value = null
    username.value = ''
    router.push('/')
  }
}

// 添加延迟隐藏功能
const startHideTimer = () => {
  if (hideTimeout.value) {
    clearTimeout(hideTimeout.value)
  }
  hideTimeout.value = window.setTimeout(() => {
    showUserProfile.value = false
    hideTimeout.value = null
  }, 300) // 300ms延迟
}

// 取消隐藏定时器
const cancelHideTimer = () => {
  if (hideTimeout.value) {
    clearTimeout(hideTimeout.value)
    hideTimeout.value = null
  }
}

// 组件挂载时加载用户信息
// 组件挂载时加载用户信息
onMounted(() => {
  const storedUserInfo = localStorage.getItem('userInfo')
  if (storedUserInfo) {
    try {
      userInfo.value = JSON.parse(storedUserInfo)
      username.value = userInfo.value.username || '用户'
    } catch (e) {
      console.error('解析用户信息失败:', e)
    }
  } else {
    // 如果没有用户信息，可能是从其他地方跳转过来的
    username.value = '用户'
  }
})

// 计算属性获取当前路由
const currentRoute = computed(() => router.currentRoute.value.path)

// 组件挂载时的初始化
onMounted(() => {
  console.log('AI写作创作页面已加载')
})
</script>

<style scoped>
.writing-container {
  position: relative;
  min-height: 100vh;
  width: 100vw;
}

.background-wrapper {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: #ffffff; /* 纯白色背景 */
  z-index: -1;
}

.content {
  position: relative;
  z-index: 1;
  min-height: 100vh;
}

/* 导航栏样式 */
.navbar {
  background: rgba(255, 255, 255, 0.9);
  backdrop-filter: blur(10px);
  box-shadow: 0 2px 20px rgba(0, 0, 0, 0.1);
  position: sticky;
  top: 0;
  z-index: 100;
  width: 100%;
}

.nav-content {
  max-width: 100%;
  margin: 0 auto;
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.logo h1 {
  font-size: 24px;
  color: #667eea;
  font-weight: 600;
}

.nav-links {
  display: flex;
  gap: 32px;
  align-items: center;
}

.nav-links a {
  color: #333;
  text-decoration: none;
  font-size: 15px;
  font-weight: 500;
  transition: color 0.3s;
  position: relative;
  padding: 8px 0;
}

.nav-links a:hover {
  color: #667eea;
}

.nav-links a.active {
  color: #667eea;
  font-weight: 600;
}

.nav-links a.active::after {
  content: '';
  position: absolute;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 2px;
  background: #667eea;
  border-radius: 1px;
}

/* 下拉菜单 */
.dropdown {
  position: relative;
  display: inline-block;
}

.dropdown-content {
  display: none;
  position: absolute;
  background: white;
  min-width: 160px;
  box-shadow: 0 8px 16px rgba(0, 0, 0, 0.1);
  border-radius: 8px;
  z-index: 1;
  top: 100%;
  left: 50%;
  transform: translateX(-50%);
  padding: 8px 0;
}

.dropdown:hover .dropdown-content {
  display: block;
}

.dropdown-content a {
  color: #333;
  padding: 12px 24px;
  text-decoration: none;
  display: block;
  font-size: 14px;
  transition: all 0.3s;
}

.dropdown-content a:hover {
  background: #f5f5f5;
  color: #667eea;
}

.dropdown:hover .dropbtn {
  color: #667eea;
}

.user-section {
  display: flex;
  align-items: center;
  gap: 12px;
  position: relative;
}

/* 用户头像按钮样式 */
.user-avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 16px;
  cursor: pointer;
  transition: all 0.3s ease;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
}

.user-avatar:hover {
  transform: scale(1.05);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
}

/* 用户信息悬浮面板 */
.user-profile-popup {
  position: absolute;
  top: 50px;
  right: 0;
  width: 280px;
  background: white;
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
  z-index: 1000;
  padding: 20px;
  animation: fadeIn 0.3s ease;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.profile-header {
  display: flex;
  flex-direction: column;
  align-items: center;
  margin-bottom: 20px;
  padding-bottom: 20px;
  border-bottom: 1px solid #eee;
}

.profile-avatar {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  font-size: 24px;
  margin-bottom: 12px;
}

.profile-name {
  font-size: 18px;
  font-weight: 600;
  color: #333;
}

.profile-details {
  margin-bottom: 20px;
}

.profile-item {
  display: flex;
  justify-content: space-between;
  margin-bottom: 12px;
}

.profile-item:last-child {
  margin-bottom: 0;
}

.item-label {
  color: #666;
  font-size: 14px;
}

.item-value {
  color: #333;
  font-size: 14px;
  font-weight: 500;
}

.profile-actions {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.profile-action-btn {
  padding: 10px 16px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s;
  text-align: center;
}

.profile-action-btn:hover {
  background: #f5f5f5;
}

.profile-action-btn.logout {
  background: #fff5f5;
  color: #e53e3e;
}

.profile-action-btn.logout:hover {
  background: #ffebee;
}

.login-btn {
  padding: 8px 20px;
  border: none;
  border-radius: 6px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s;
  background: #667eea;
  color: white;
}

.login-btn:hover {
  background: #5568d3;
}

/* AI写作页面主要内容 */
.writing-main {
  width: 100vw;
  min-height: calc(100vh - 200px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 40px 24px;
}

.writing-content {
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

.page-title {
  font-size: 32px;
  font-weight: 700;
  color: #2D3E40;
  text-align: center;
  margin-bottom: 16px;
}

.page-description {
  font-size: 18px;
  color: #4A4A4A;
  text-align: center;
  margin-bottom: 40px;
  max-width: 800px;
  margin-left: auto;
  margin-right: auto;
  line-height: 1.6;
}

/* 步骤指示器 */
.steps-indicator {
  display: flex;
  justify-content: center;
  gap: 30px;
  margin-bottom: 50px;
  position: relative;
}

.steps-indicator::before {
  content: '';
  position: absolute;
  top: 20px;
  left: 15%;
  right: 15%;
  height: 2px;
  background: #e0e0e0;
  z-index: 1;
}

.step {
  display: flex;
  flex-direction: column;
  align-items: center;
  z-index: 2;
}

.step-number {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #e0e0e0;
  color: #999;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: bold;
  margin-bottom: 10px;
  transition: all 0.3s;
}

.step-label {
  font-size: 16px;
  color: #999;
  font-weight: 500;
}

.step.active .step-number {
  background: #667eea;
  color: white;
}

.step.active .step-label {
  color: #667eea;
}

.step.completed .step-number {
  background: #4CAF50;
  color: white;
}

.step.completed .step-label {
  color: #4CAF50;
}

/* 创作步骤 */
.creation-step {
  animation: fadeIn 0.5s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.creation-step h3 {
  font-size: 28px;
  font-weight: 600;
  color: #333;
  text-align: center;
  margin-bottom: 30px;
}

/* 文体选择 */
.genre-selection,
.content-guidance,
.generation-section {
  background: white;
  border-radius: 12px;
  padding: 30px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
  margin-bottom: 30px;
}

.tags-container {
  display: flex;
  flex-wrap: wrap;
  gap: 15px;
  margin-bottom: 30px;
}

.tag {
  background: #f0f0f0;
  color: #666;
  padding: 10px 20px;
  border-radius: 30px;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s;
}

.tag:hover {
  background: #e0e0e0;
  transform: translateY(-2px);
}

.tag.selected {
  background: #667eea;
  color: white;
  box-shadow: 0 4px 12px rgba(102, 126, 234, 0.3);
}

.theme-tag {
  background: rgba(102, 126, 234, 0.1);
  color: #667eea;
}

.theme-tag:hover {
  background: rgba(102, 126, 234, 0.2);
}

.recommendation-tag {
  background: rgba(76, 175, 80, 0.1);
  color: #4CAF50;
}

.recommendation-tag:hover {
  background: rgba(76, 175, 80, 0.2);
}

.selected-combination,
.theme-selection {
  padding-top: 20px;
  border-top: 1px dashed #e0e0e0;
}

.selected-combination h4,
.theme-selection h4 {
  margin-bottom: 15px;
}

.combination-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.combination-tag {
  background: #667eea;
  color: white;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 14px;
}

/* 内容引导 */
.recommendation-section,
.input-section {
  margin-bottom: 30px;
}

.recommendation-section:last-child,
.input-section:last-child {
  margin-bottom: 0;
}

.recommendation-group {
  margin-bottom: 30px;
}

.recommendation-group:last-child {
  margin-bottom: 0;
}

.recommendation-group h4,
.input-group h4 {
  font-size: 20px;
  font-weight: 600;
  color: #333;
  margin-bottom: 20px;
}

.suggestion-content {
  background: #f8f9fa;
  border-radius: 8px;
  padding: 15px;
  font-size: 16px;
  color: #555;
  line-height: 1.6;
}

.requirements-input {
  width: 100%;
  min-height: 120px;
  padding: 16px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 16px;
  resize: vertical;
  margin-bottom: 20px;
}

.keyword-input-area {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
}

.keyword-input {
  flex: 1;
  padding: 12px 16px;
  border: 1px solid #ddd;
  border-radius: 8px;
  font-size: 16px;
}

.add-keyword-btn {
  padding: 12px 20px;
  background: #667eea;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s;
}

.add-keyword-btn:hover {
  background: #5568d3;
  transform: translateY(-2px);
}

.selected-keywords {
  margin-top: 20px;
  padding-top: 20px;
  border-top: 1px dashed #e0e0e0;
}

.selected-keywords h4 {
  margin-bottom: 15px;
}

.keywords-container {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.keyword-tag {
  background: #667eea;
  color: white;
  padding: 8px 16px;
  border-radius: 20px;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 5px;
}

.remove-keyword {
  background: none;
  border: none;
  color: white;
  font-size: 16px;
  cursor: pointer;
  padding: 0;
  margin-left: 5px;
}

/* 生成与编辑 */
.generation-summary {
  background: #f8f9fa;
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 30px;
}

.generation-summary h4 {
  margin-bottom: 15px;
}

.summary-content p {
  margin-bottom: 10px;
  font-size: 16px;
  color: #555;
}

.summary-content strong {
  color: #333;
}

.generate-btn {
  padding: 14px 32px;
  background: #667eea;
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.3s;
  display: block;
  margin: 0 auto;
}

.generate-btn:hover {
  background: #5568d3;
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(102, 126, 234, 0.3);
}

.generate-btn:disabled {
  background: #cccccc;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* 生成状态 */
.generation-status {
  text-align: center;
  padding: 30px;
}

.loading-spinner {
  width: 50px;
  height: 50px;
  border: 5px solid #f3f3f3;
  border-top: 5px solid #667eea;
  border-radius: 50%;
  animation: spin 1s linear infinite;
  margin: 0 auto 20px;
}

@keyframes spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}

.generation-status p {
  font-size: 18px;
  color: #666;
}

/* 文字编辑器 */
.editor-section {
  margin-top: 40px;
  animation: fadeIn 0.5s ease;
}

.editor-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.editor-header h4 {
  font-size: 24px;
  font-weight: 600;
  color: #333;
  margin: 0;
}

.word-count {
  font-size: 16px;
  color: #666;
}

.editor-container {
  background: white;
  border-radius: 12px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.1);
  overflow: hidden;
  margin-bottom: 30px;
}

.editor-toolbar {
  background: #f8f9fa;
  border-bottom: 1px solid #e9ecef;
  padding: 10px;
  display: flex;
  gap: 5px;
  flex-wrap: wrap;
}

.toolbar-btn {
  background: white;
  border: 1px solid #ddd;
  border-radius: 4px;
  padding: 8px 12px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.3s;
}

.toolbar-btn:hover {
  background: #e9ecef;
}

.editor-content {
  min-height: 300px;
  padding: 20px;
  font-size: 16px;
  line-height: 1.6;
  outline: none;
}

.editor-content:focus {
  outline: none;
}

.editor-content h1 {
  font-size: 2em;
  font-weight: bold;
  margin: 0.67em 0;
}

.editor-content h2 {
  font-size: 1.5em;
  font-weight: bold;
  margin: 0.83em 0;
}

.editor-content p {
  margin-bottom: 16px;
}

.editor-actions {
  display: flex;
  justify-content: center;
  gap: 20px;
}

.action-btn {
  padding: 12px 30px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s;
  background: #f5f5f5;
  color: #666;
}

.action-btn:hover {
  background: #e0e0e0;
  transform: translateY(-2px);
}

.action-btn.primary {
  background: #4CAF50;
  color: white;
}

.action-btn.primary:hover {
  background: #45a049;
}

/* 操作按钮 */
.step-actions,
.generation-actions {
  display: flex;
  justify-content: center;
  gap: 20px;
  margin-top: 30px;
}

.prev-btn,
.next-btn {
  padding: 12px 30px;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.3s;
}

.prev-btn {
  background: #f5f5f5;
  color: #666;
}

.prev-btn:hover {
  background: #e0e0e0;
  transform: translateY(-2px);
}

.next-btn {
  background: #667eea;
  color: white;
}

.next-btn:hover {
  background: #5568d3;
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(102, 126, 234, 0.3);
}

.next-btn:disabled {
  background: #cccccc;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* 底部 */
.footer {
  background: #333;
  color: white;
  text-align: center;
  padding: 40px 24px;
  margin-top: 80px;
  width: 100%;
}

.footer p {
  font-size: 14px;
  opacity: 0.8;
}

/* 响应式 */
@media (max-width: 768px) {
  .steps-indicator {
    gap: 15px;
  }
  
  .steps-indicator::before {
    left: 10%;
    right: 10%;
  }
  
  .step-label {
    font-size: 14px;
  }
  
  .creation-step h3 {
    font-size: 24px;
  }
  
  .genre-selection,
  .content-guidance,
  .generation-section {
    padding: 20px;
  }
  
  .tags-container {
    gap: 10px;
  }
  
  .tag {
    padding: 8px 16px;
    font-size: 13px;
  }
  
  .keyword-input-area {
    flex-direction: column;
  }
  
  .step-actions,
  .generation-actions,
  .editor-actions {
    flex-direction: column;
    gap: 15px;
  }
  
  .prev-btn,
  .next-btn,
  .generate-btn,
  .action-btn {
    width: 100%;
  }
  
  .editor-header {
    flex-direction: column;
    gap: 10px;
    align-items: flex-start;
  }
}
</style>